<?php

// $Id$
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/**
 * Function used to display an horizontal menu inside the admin panel
 *
 * Enable webmasters to navigate thru the module's features.
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
 *
 * @package News
 * @author - stolen to the Newbb team ;-)
 * @copyright	(c) The Xoops Project - www.xoops.org
*/

include '../xoops_version.php';

function adminmenu($currentoption = 0, $breadcrumb = '')
{
global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
$myts =& MyTextSanitizer::getInstance();
	
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 0px solid black; border-right: 0px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 0px solid black; border-right: 0px solid black; margin-bottom: 0px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>";

	$tblColors = array();
	$tblColors = array_pad ($tblColors, count($adminmenu), ""); 
	
	if($currentoption>=0) {
		$tblColors[$currentoption] = 'current';
	}
	echo "<div id='buttontop' style='border-right: 1px solid black;border-left: 1px solid black;margin-bottom:8px;padding-bottom:0;'>"; 
	echo "<table style='width: 100%; padding:0;' cellspacing='0'><tr>";
	echo "<td style=\"width: 60%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">"; if(isset($modversion['config'])){echo"<a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=".$xoopsModule->getVar('mid')."\">Preferences</a> | ";} echo"<a href=\"../index.php\">Go to module</a>"; if(isset($modversion['hasHelp']) && $modversion['hasHelp']==1){echo"| <a href=\"".$modversion['helpUrl']."\">Help</a>";} echo "</td>";
	echo "<td style=\"width: 40%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\"><b>" . $xoopsModule->name() . "  </b> " . $breadcrumb . "</td>";
	echo "</tr></table>";
	echo "<div id='buttonbar'>";
	echo "<ul>";
	for($i=0; $i<count($adminmenu); ++$i){ //XOOPS_ROOT_PATH."/modules/".$modversion['dirname']."/admin/
		echo "<li id='" . $tblColors[$i] . "'><a href='".XOOPS_URL."/modules/".$modversion['dirname']."/".$adminmenu[$i]['link']."'><span>" . $adminmenu[$i]['title'] . "</span></a></li>\n";
	}
	echo "</ul></div>";
	echo "</div><div style='margin-bottom:2px;'>&nbsp;</div>";
	
}



function news_collapsableBar($tablename = '', $iconname = '')
{

    ?>
	<script type="text/javascript"><!--
	function goto_URL(object)
	{
		window.location.href = object.options[object.selectedIndex].value;
	}

	function toggle(id)
	{
		if (document.getElementById) { obj = document.getElementById(id); }
		if (document.all) { obj = document.all[id]; }
		if (document.layers) { obj = document.layers[id]; }
		if (obj) {
			if (obj.style.display == "none") {
				obj.style.display = "";
			} else {
				obj.style.display = "none";
			}
		}
		return false;
	}

	var iconClose = new Image();
	iconClose.src = '../images/close12.gif';
	var iconOpen = new Image();
	iconOpen.src = '../images/open12.gif';

	function toggleIcon ( iconName )
	{
		if ( document.images[iconName].src == window.iconOpen.src ) {
			document.images[iconName].src = window.iconClose.src;
		} else if ( document.images[iconName].src == window.iconClose.src ) {
			document.images[iconName].src = window.iconOpen.src;
		}
		return;
	}

	//-->
	</script>
	<?php
	echo "<h4 style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href='#' onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
}




function address(){
	global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;

	$result = $xoopsDB->query( "SELECT mailing_addy FROM ".$xoopsDB->prefix('contact_form_contact_info')."" ) ;
	if ($result) {
	$myrow = $xoopsDB->fetchArray($result);
	$addy = $myrow['mailing_addy'];
	}
	
		
	
	
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Mailing Address', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormTextArea('Enter Your Station\'s Mailing Address:', 'addy', $addy, 5, 35), $required = false);
	$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'change_address'));
	$form->display();
}



function voice(){
	global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
	$result = $xoopsDB->query( "SELECT voice FROM ".$xoopsDB->prefix('contact_form_contact_info')."" ) ;
	if ($result) {
	$myrow = $xoopsDB->fetchArray($result);
	$voice = $myrow['voice'];
	}
	

	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Voice Numbers', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormTextArea('Enter Your Station\'s Voice Phone Numbers:', 'voice', $voice, 5, 35), $required = false);
	$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'change_voice'));
	$form->display();
}




function fax(){
	global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
	$result = $xoopsDB->query( "SELECT fax FROM ".$xoopsDB->prefix('contact_form_contact_info')."" ) ;
	if ($result) {
	$myrow = $xoopsDB->fetchArray($result);
	$fax = $myrow['fax'];
	}
	
		
	
	
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Fax Number', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormTextArea('Enter Your Station\'s Fax Number(s):', 'fax', $fax, 5, 35), $required = false);
	$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'change_fax'));
	$form->display();
}



function hours(){
	global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
	$result = $xoopsDB->query( "SELECT hours FROM ".$xoopsDB->prefix('contact_form_contact_info')."" ) ;
	if ($result) {
	$myrow = $xoopsDB->fetchArray($result);
	$hours = $myrow['hours'];
	}
	
		
	
	
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Office Hours', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormTextArea('Enter Your Station\'s Office Hours:', 'hours', $hours, 5, 35), $required = false);
	$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'change_hours'));
	$form->display();
}




function subject($sub=''){
	global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
	$myts =& MyTextSanitizer::getInstance();

	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("contact_form_recipients")." ORDER BY weight ASC" ) ;
		if ( $result ) {
			$dataArray = array();
			while ( $myrow = $xoopsDB->fetchArray($result) ) {
			$dataArray[] = $myrow;
			}
		}
	
	
	news_collapsableBar('sectionmanager', 'toptopicsmanager'); 
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . XOOPS_URL . "/modules/contact_form/images/close12.gif' alt='' /></a>&nbsp; Subject Lines". ' (' . count($dataArray) . ')'."</h4>";
	echo "<div id='sectionmanager'>
	<!--BEGIN COLLAPSABLE DIV-->
	
	<table style='margin-top:8px;' width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>
		<tr class='bg3' style='text-align:left;font-weight:600;'>
			<td>Subject Line</td>
			<td>Recipient</td>
			<td>Functions</td>
		</tr>";
		
		function oddEven($ID){
			if($ID&1){
				return "odd";
			}else{
				return "even";
			}
		}
		
		
		for($i=0; $i < count($dataArray); $i++){
		
		if ($i != 0) {
					$moveup = "	<a href='admin_formaction.php?direction=up&previous=".$dataArray[$i-1]['ID']."&op=move&Rid=".$dataArray[$i]['ID']."&weight=".($dataArray[$i]['weight']-1)."'>
							<img src='../images/icon/up.gif' alt='Move This Item Down'></a>";
					} else { 
					$moveup = "	<img src='../images/icon/noup.gif' alt='Move This Item Down'>"; 
					}
			
					if ($i != (count($dataArray) - 1)) {
					$movedown = "<a href='admin_formaction.php?direction=down&next=".$dataArray[$i+1]['ID']."&op=move&Rid=".$dataArray[$i]['ID']."&weight=".($dataArray[$i]['weight']+1)."'>
							<img src='../images/icon/down.gif' alt='Move This Item Down'></a>";
					} else {
					 $movedown = "<img src='../images/icon/nodown.gif' alt='Move This Item Down'>";
					}
		
	echo"<tr class='".oddEven($i)."'  style='text-align:left;'>
			<td style='padding-left:0px;'>".stripslashes($dataArray[$i]['subject'])."</td>
			<td style='padding-left:0px;'>".stripslashes($dataArray[$i]['recipient'])."</td>
			<td style='padding-left:0px;'><a href='index.php?op=editSubject&amp;ID=".$dataArray[$i]['ID']."&amp;currentID=4'>Edit</a> - <a href='index.php?op=deleteSubject&amp;currentID=4&amp;ID=".$dataArray[$i]['ID']."&amp;subject=".$myts->htmlSpecialChars(stripslashes($dataArray[$i]['subject']))."'>Delete</a> &nbsp; $moveup &nbsp; $movedown</td> 
		</tr>";
	}
	
	echo"</table>	
	<!--END COLLAPSABLE DIV-->
	</div><p></P>";
	
	
	if(!isset($_GET['subject'])){
		$_GET['subject'] = "";
	}
	
	if(!isset($_GET['recipient'])){
		$_GET['recipient'] = "";
	}
	
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Add Subject Line and Recipients For Your Contact Form', 'config', 'admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormText('Subject Line:', 'subject', '35', '50', $_GET['subject']), $required = true);
	$form->addElement(new XoopsFormText('Email Recipient For Messages With This Subject Line:', 'recipient', '35', '50', $_GET['recipient']), $required = true);
	$form->addElement(new XoopsFormButton('', 'update', 'Enter', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'add_subject'));
	$form->display();	

}




function deleteSubject(){
    global $xoopsDB, $xoopsConfig, $xoopsModule;
	$myts =& MyTextSanitizer::getInstance();
	xoops_confirm(array('action'=>'delete_subject', 'ID'=>$_GET['ID'],'title'=>$_GET['subject']), 'admin_formaction.php', "Are you sure you want to remove this subject line: ".$myts->htmlSpecialChars(stripslashes($_GET['subject']))."?");
}



function editSubject(){
    global $xoopsDB, $xoopsConfig, $xoopsModule;
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("contact_form_recipients")." WHERE ID = '".$_GET['ID']."'" ) ;
	$myrow = $xoopsDB->fetchArray($result);
	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Edit Subject Line / Recipient', 'config', '../admin/admin_formaction.php', 'POST');
	$form->addElement(new XoopsFormText('Subject Line:', 'subject', '35', '50', stripslashes($myrow['subject'])), $required = true);
	$form->addElement(new XoopsFormText('Email Recipient For Messages With This Subject Line:', 'recipient', '35', '50', $myrow['recipient']), $required = true);
	
	$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
	$form->addElement(new XoopsFormHidden('action', 'edit_subject'));
	$form->addElement(new XoopsFormHidden('ID', $_GET['ID']));
	$form->display();
}

?>
